#!/usr/bin/python
# -*- coding: UTF-8 -*-

import pymysql

# 打开数据库连接
db = pymysql.connect(host='127.0.0.1',
                             user='root',
                             password='tc123456',
                             database='cgw',
                             cursorclass=pymysql.cursors.DictCursor)

# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()
sql = "select * from arrangement "
# 使用 execute()  方法执行 SQL 查询
cursor.execute(sql)
# 使用 fetchone() 方法获取单条数据.
rows = cursor.fetchall()

fromin={}

for row in rows:
    if not fromin.get("select * from paydb.T_CMP_TYPE_RECHARGELIST"+row['TABLEID']):
        fromin["select * from paydb.T_CMP_TYPE_RECHARGELIST"+row['TABLEID']]="'"+row['OBJECTID']+"'"
    else:
        fromin["select * from paydb.T_CMP_TYPE_RECHARGELIST"+row['TABLEID']]+=",'"+row['OBJECTID']+"'"


for k in fromin.keys():
    print(k +" where objectid in ("+fromin[k]+") union all")


db.close()

